﻿Imports System.Data.OleDb
Imports System.Globalization
Imports System.Globalization.CultureInfo
Imports System.IO
Public Class displayName
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If User.Identity.IsAuthenticated = False Then
            Response.Redirect("Default.aspx")
        End If
    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("BookMeetConnString").ConnectionString)
        Dim SqlString
        Dim cmd
        If Not fu_avatar.HasFile Then
            SqlString = "Insert into userprofiles(EmailAddress,DOB,Location,Description,Profession,Smoker,Drinker,EducationLevel,MaritalStatus,TravellerName,AvatarURL) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8,@f9,@f10,@f11)"
            cmd = New OleDbCommand(SqlString, oleDbConn)
            cmd.Parameters.AddWithValue("@f1", email.Text)
            cmd.Parameters.AddWithValue("@f2", DateTime.ParseExact(dob.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture))
            cmd.Parameters.AddWithValue("@f3", dd_userlocation.SelectedValue)
            cmd.Parameters.AddWithValue("@f4", description.Text)
            cmd.Parameters.AddWithValue("@f5", profession.SelectedValue)
            cmd.Parameters.AddWithValue("@f6", smoker.SelectedValue)
            cmd.Parameters.AddWithValue("@f7", drinker.SelectedValue)
            cmd.Parameters.AddWithValue("@f8", educationlevel.SelectedValue)
            cmd.Parameters.AddWithValue("@f9", maritalstatus.SelectedValue)
            cmd.Parameters.AddWithValue("@f10", User.Identity.Name)
            cmd.Parameters.AddWithValue("@f11", "UserProfileAvatar/no_image.jpg")
        Else
            SqlString = "Insert into userprofiles(EmailAddress,DOB,Location,Description,Profession,Smoker,Drinker,EducationLevel,MaritalStatus,TravellerName,AvatarURL) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8,@f9,@f10,@f11)"
            cmd = New OleDbCommand(SqlString, oleDbConn)
            cmd.Parameters.AddWithValue("@f1", email.Text)
            cmd.Parameters.AddWithValue("@f2", DateTime.ParseExact(dob.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture))
            cmd.Parameters.AddWithValue("@f3", dd_userlocation.SelectedValue)
            cmd.Parameters.AddWithValue("@f4", description.Text)
            cmd.Parameters.AddWithValue("@f5", profession.SelectedValue)
            cmd.Parameters.AddWithValue("@f6", smoker.SelectedValue)
            cmd.Parameters.AddWithValue("@f7", drinker.SelectedValue)
            cmd.Parameters.AddWithValue("@f8", educationlevel.SelectedValue)
            cmd.Parameters.AddWithValue("@f9", maritalstatus.SelectedValue)
            cmd.Parameters.AddWithValue("@f11", User.Identity.Name)
            cmd.Parameters.AddWithValue("@f10", "UserProfileAvatar/" & User.Identity.Name & ".jpg")
            Dim fileLocationOnServerHardDisk = Request.MapPath("UserProfileAvatar") & "/" & User.Identity.Name & ".jpg"
            fu_avatar.SaveAs(fileLocationOnServerHardDisk)
        End If
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        oleDbConn.Close()
        Response.Redirect("~/Default.aspx")
    End Sub
End Class